/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/9/5  14:24
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.cn;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.ant.cn.activities.Demo01;
import com.ant.cn.activities.Demo02;
import com.ant.cn.activities.Demo03;
import com.ant.cn.activities.Demo04;
import com.ant.cn.activities.Demo05;
import com.ant.cn.activities.Demo06;
import com.ant.cn.activities.Demo07;
import com.ant.cn.activities.Demo08;
import com.ant.cn.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by baichuan on 2016/9/5.
 */
public class IndexActivity extends BaseActivity {
    private ListView lv;
    private List<String> slt;
    private List<Class> clt;
    private ArrayAdapter<String> adapter;

    @Override
    public int getLaout() {
        slt = new ArrayList<>();
        clt = new ArrayList<>();

        return R.layout.ac_main;
    }

    @Override
    public void initView() {
        lv = (ListView) findViewById(R.id.ac_main_listview);

    }

    public void getData() {
        slt.add("demo001");
        clt.add(Demo01.class);
        slt.add("demo002");
        clt.add(Demo02.class);
        slt.add("demo003");
        clt.add(Demo03.class);
        slt.add("demo004");
        clt.add(Demo04.class);
        slt.add("demo005");
        clt.add(Demo05.class);
        slt.add("demo006");
        clt.add(Demo06.class);
        slt.add("demo007");
        clt.add(Demo07.class);
        slt.add("demo008");
        clt.add(Demo08.class);
    }

    @Override
    public void initData() {
        getData();

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, slt);
        lv.setAdapter(adapter);
    }

    @Override
    public void initListener() {
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent in = new Intent(IndexActivity.this, clt.get(i));
                IndexActivity.this.startActivity(in);
            }
        });

    }
}
